//
//  PicVerCodeView.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/11.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "PicVerCodeView.h"
#import "CYXBaseRequest.h"
#import "BaseTextField.h"
@interface PicVerCodeView()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIImageView *codeImg;
@property (weak, nonatomic) IBOutlet BaseTextField *verCInput;
@end
@implementation PicVerCodeView

INITFROMXIB

- (void)awakeFromNib{
    [super awakeFromNib];
    self.bgView.layer.cornerRadius = 10.0;
    self.bgView.layer.masksToBounds = YES;
    LRViewBorderRadius(self.codeImg, 4, 0, [UIColor clearColor]);
    self.verCInput.placeholder = LCLocalString(@"plh_qsryzm");
    self.verCInput.placeholderColor = PlhColor;
}
- (IBAction)changeOne:(id)sender {
    [self getPicCode];
}

- (void)showInView:(UIView *)view{
    [view addSubview:self];
    [self getPicCode];
    [self show];
}

- (void)show{
    self.backgroundColor = [UIColor clearColor];
    self.bgView.transform = CGAffineTransformScale(CGAffineTransformIdentity,CGFLOAT_MIN,CGFLOAT_MIN);
    
    [UIView animateWithDuration:0.15
                     animations:^{
        self.bgView.transform = CGAffineTransformIdentity;
        self.backgroundColor = [[UIColor alloc] initWithWhite:0 alpha:0.8];
    }
                     completion:^(BOOL finished) {
     
    }];
    
}

- (void)hide{
    
    [UIView animateWithDuration:0.15
                     animations:^{
        self.backgroundColor = [UIColor clearColor];
        self.bgView.transform = CGAffineTransformScale(CGAffineTransformIdentity,0.1,0.1);
    }
                     completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (IBAction)btnAction:(UIButton *)sender {
    
    if (self.actionBlock) {
        self.actionBlock(sender.tag - 1000,self.verCInput.text);
    }
    [self hide];
}

#pragma mark-

- (void)getPicCode{
    
    [CYXBaseRequest getWithUrl:self.gvcApi param:nil resultClass:[UIImage class] success:^(id res) {
        self.codeImg.image = res;
        CYXLog(@"%@",res)
    } failure:^(NSError *error) {
        CYXLog(@"%@",error)
    }];
}

@end
